﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BankOCR
{
    public class HashVerifier: IHashVerifier
    {
        public bool IsHashCorrect(string accountNumber)
        {
            if (accountNumber.Length != 9)
                throw new InvalidOperationException("Tried to compute hash of invalid account number: " + accountNumber);
            var hash = accountNumber.Select(c => int.Parse(c.ToString())).Reverse().Select((digit, idx) => (idx + 1) * digit).Sum();
            return hash % 11 == 0;
        }
    }
}
